package cn.itcast.java.thread;

/**
 * Author itcast
 * Date 2021/10/14 7:12
 * Desc TODO
 */
public class Demo02 {
    private static final String lockA="锁A";
    private static final String lockB="锁B";

    public static void main(String[] args) {
        new Thread("zhangsan"){
            @Override
            public void run() {
                while(true) {
                    synchronized (lockA) {
                        System.out.println("获取到锁A" + lockA + " 等到 " + lockB);
                        synchronized (lockB) {
                            System.out.println("获取到B" + lockB + " 成功进入小黑屋");
                        }
                    }
                }
            }
        }.start();

        new Thread("lisi"){
            @Override
            public void run() {
                while(true) {
                    synchronized (lockB) {
                        System.out.println("获取到锁A" + lockB + " 等到 " + lockA);
                        synchronized (lockA) {
                            System.out.println("获取到B" + lockA + " 成功进入小黑屋");
                        }
                    }
                }
            }
        }.start();
    }
}
